package engine.logic.login
{
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	
	import newx.com.config.StaticIni;
	import newx.com.loader.SwfLoader;

	public class LoginGroup implements ILoginUI
	{
//		private var _serverSelectUI:ILoginUI;
		private var _userInfoForm:ILoginUI;
		private var _bg:MovieClip;
		
//		private 
		
		private var _completeCallBack:Function;
		
		
		public static var _ip		:String
		public static var _port		:int;
		public static var _serverId	:String;
		public static var _userName:String;
		public static var _password:String;
		public static var _sIdentity:String;
		private var _parentMc:MovieClip;
		
		public function LoginGroup(mc:MovieClip,loginContainer:MovieClip)
		{
			_parentMc	=	loginContainer;	
//			_serverSelectUI=new ServerSelectUI(mc.getChildByName("serverList") as MovieClip,loginContainer);
//			_serverSelectUI.completeCallBack=serverSelectCompleteCB;
			
			_userInfoForm=new UserInfoForm(mc.getChildByName("dl_mc") as MovieClip,loginContainer);
			_userInfoForm.completeCallBack=userInfoCompleteCB;
		}
		
		public function show(info:Object=null):void
		{
			try
			{
				var ip:String	=ModelLocator.getInstance().GetProperties("ip");
				var port:String	=ModelLocator.getInstance().GetProperties("port");
				if(ip&&port)
				{
					_userInfoForm.show();
					_ip		= 	ip;
					_port	=	int(port);
					_serverId	=	ModelLocator.getInstance().GetProperties("serverId");
				}
				else
				{
//					_serverSelectUI.show();
				}
			}
			catch(e:*)
			{
//				_serverSelectUI.show();
			}
		}
		
		public function hide():void
		{
			_userInfoForm.hide();
			
			if(	null	!=	_bg	&&	null	!=	_bg.parent)
				_bg.parent.removeChild(_bg);
		}
		
		public function recycle():void
		{
			_userInfoForm	=	null;
//			_serverSelectUI	=	null;
		}
		
		public function set completeCallBack(cb:Function):void
		{
			_completeCallBack=cb;
		}
		
		private function	serverSelectCompleteCB(info:Object):void
		{
			if(info	&&	info.ip	&& 	info.port)
			{
				_ip=info.ip;
				_port=info.port;
				_serverId=info.serverId;
				
				ServerSelectUI(info.target).hide();
				_userInfoForm.show();
			}
			else
			{
//				_loginAlert.showAlert(getServerSelectTip());
				LoginAlert.showAlert(getServerSelectTip());
			}
		}
		
		private function userInfoCompleteCB(obj:Object):void
		{
			_userName=obj.userName;
			_password=obj.password;
			
			if(null		!=	_completeCallBack	)
			{
				var groupInfo:Object={
											ip		:_ip,
											port	:_port,
											serverId:_serverId,
											userName:_userName,
											password:_password
										};
				_completeCallBack(groupInfo);
			}
			
		}
		
		private function getServerSelectTip():String
		{
			return StaticIni.getSwfLangStr("UIStr_1000873");
		}

//		public function get serverSelectUI():ILoginUI
//		{
//			return _serverSelectUI;
//		}
		public function get bg():MovieClip
		{
			return _bg;
		}

		
	}
}